import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:ytbusiness/models/notify_list_model.dart';
import 'package:ytbusiness/repository/public_request.dart';
import 'package:ytbusiness/state/base_model.dart';
import 'package:ytbusiness/state/user_role.dart';

///消息通知
class NotifyViewModel extends BaseModel {
  PublicRequest _publicRequest;
  List<NotifyItem> notifyList;

  NotifyViewModel(PublicRequest publicRequest) {
    this._publicRequest = publicRequest;
  }

  //获取公告信息
  getNotify(BuildContext context, {Map<String, dynamic> data}) {
    _publicRequest.getNotify(context: context, data: data).then((value) {
      notifyList = value?.notifyData?.notifyList ?? [];
      notifyListeners();
    });
  }

  ///刷新
  Future<void> onRefresh({BuildContext context}) async {
    print("正在刷新");

    getNotify(context, data: {
      "role_id": Provider.of<UserRole>(context, listen: false).role,
      "page_size": 1,
    });
  }

  ///加载
  Future<void> onLoad() async {
    await Future.delayed(Duration(seconds: 2), () {
      print("正在加载");
      notifyListeners();
    });
  }
}
